<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>筛选数组去除0的数组</title>
</head>

<body>
  <script>
    // 将数组 [2, 0, 6, 1, 77, 0, 52, 0, 25, 7]筛选，形成一个不包含 0 的新数组
    let arr = [2, 0, 6, 1, 77, 0, 52, 0, 25, 7]

    // 1. 准备一个新的数组 newArr
    let newArr = []
    // 2. 遍历旧数组，如果数组元素不等于0，把满足条件的数组元素追加给新数组newArr
    for (let i = 0; i < arr.length; i++) {
      console.log(arr[i])
      if (arr[i] != 0) {
        newArr.push(arr[i])
      }

    }
    console.log(newArr)
  </script>
</body>

</html>